package com.jyx.designpatterns.mediator;


public class ConcreteMediator implements Mediator {
	private ColleagueA colleagueA;
	private ColleagueB colleagueB;
	private ColleagueC colleagueC;
	
	//中介者注册三个国家的引用
	public void registerColleagueA(ColleagueA colleagueA)
	{
		this.colleagueA=colleagueA;
	}
	public void registerColleagueB(ColleagueB colleagueB)
	{
		this.colleagueB=colleagueB;
	}
	public void registerColleagueC(ColleagueC colleagueC)
	{
		this.colleagueC=colleagueC;
	}
	//中介者进行调停
	public void deliverMess(Colleague colleague, String[] mess) {
		if(colleague == colleagueA)
		{
			if(mess.length>=2)
			{
				colleagueB.receiverMess(colleague.getName()+mess[0]);
				colleagueC.receiverMess(colleague.getName()+mess[1]);
			}
		}else if(colleague == colleagueB)
		{
			if(mess.length>=2)
			{
				colleagueA.receiverMess(colleague.getName()+mess[0]);
				colleagueC.receiverMess(colleague.getName()+mess[1]);
			}
		}else if(colleague == colleagueC)
		{
			if(mess.length>=2)
			{
				colleagueA.receiverMess(colleague.getName()+mess[0]);
				colleagueB.receiverMess(colleague.getName()+mess[1]);
			}
		}
	}
}